﻿using System.Runtime.InteropServices;

namespace EasyLottery.Utils
{
    class MusicUtils
    {
        //private static uint SND_ASYNC = 0x0001;
        //private static uint SND_FILENAME = 0x00020000;

        [DllImport("winmm.dll")]
        private static extern uint mciSendString(string lpstrCommand,
            string lpstrReturnString, uint uReturnLength, uint hWndCallback);

        public static void StopAndPlay(string fileName)
        {
            Stop();
            Play(fileName);
        }

        public static void Play(string fileName)
        {
            mciSendString(@"open """ + fileName + @""" alias temp_alias", null, 0, 0);
            mciSendString("play temp_alias repeat", null, 0, 0);
        }

        public static void Stop()
        {
            mciSendString(@"close temp_alias", null, 0, 0);
        }
    }
}
